package com.metasoft.flex.dto {
	
	import com.metasoft.flex.dto.XMLInfo;

	public class CreationPref
	implements XMLInfo {
		
		// Elements 
		private var title:String;
		private var creatorName:String;
		private var keyword:String;
		private var tool:String;
		// TODO location if needed 
		//private var location:String;
		
		private var datePeriodTimePoint:String;
		private var datePeriodDuration:String;
		
		// Attributes
		private var creatorPrefValue:String;
		private var datePeriodPrefValue:String;
		
		public function set Title(title:String):void {
			this.title = new String();
			this.title = title;
		}
		
		public function set CreatorName(creatorName:String):void {
			this.creatorName = new String();
			this.creatorName = creatorName;
		}
		
		public function set Keyword(keyword:String):void {
			this.keyword = new String();
			this.keyword = keyword;
		}
		
		public function set DatePeriodTimePoint(dpTimePoint:String):void {
			this.datePeriodTimePoint = new String();
			this.datePeriodTimePoint = dpTimePoint; 
		} 
		
		public function set DatePeriodDuration(dpDuration:String):void {
			this.datePeriodDuration = new String();
			this.datePeriodDuration = dpDuration; 
		} 
		
		public function set Tool(tool:String):void {
			this.tool = new String();
			this.tool = tool;
		}
		
		/**
		 * Converts this object to XML String.
		 */
		public function toXMLString():String {
			
			var cpInfo:String = new String();
			
			cpInfo = cpInfo.concat("<urn1:CreationPreferences>"); 
			
			if (title != null) {
				cpInfo = cpInfo.concat("<urn1:Title>"); 
				cpInfo = cpInfo.concat(this.title);
				cpInfo = cpInfo.concat("</urn1:Title>");
			}
			
			if (creatorName != null || creatorPrefValue != null) {
				cpInfo = cpInfo.concat("<urn1:Creator preferenceValue=\"");
				cpInfo = cpInfo.concat(this.creatorPrefValue);
				cpInfo = cpInfo.concat(">");
				cpInfo = cpInfo.concat("<urn1:Character><urn1:GivenName>");
				cpInfo = cpInfo.concat(this.creatorName);
				cpInfo = cpInfo.concat("</urn1:GivenName></urn1:Character>");
				cpInfo = cpInfo.concat("</urn1:Creator>");
			}
			
			if (keyword != null) {
				cpInfo = cpInfo.concat("<urn1:Keyword>");
				cpInfo = cpInfo.concat(this.keyword);
				cpInfo = cpInfo.concat("</urn1:Keyword>");
			}
			
			if (datePeriodTimePoint != null || datePeriodDuration != null) {
				cpInfo = cpInfo.concat("<urn1:DatePeriod preferenceValue=\"");
				
				if (datePeriodPrefValue != null) {
					cpInfo = cpInfo.concat(this.datePeriodPrefValue);					
				}
				
				if (datePeriodTimePoint != null) {
					cpInfo = cpInfo.concat(this.datePeriodTimePoint);
				}
				
				if (datePeriodDuration != null) {
					cpInfo = cpInfo.concat(this.datePeriodDuration);
				}
				cpInfo = cpInfo.concat("</urn1:DatePeriod>");
			}
			
			if (tool != null) {
				cpInfo = cpInfo.concat("<urn1:Tool>");
				cpInfo = cpInfo.concat(this.tool);
				cpInfo = cpInfo.concat("</urn1:Tool>");				
			}
			cpInfo = cpInfo.concat("</urn1:CreationPreferences>");

			return cpInfo;
		}
	}
}